﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using PhotoViewerLib;
using System.Drawing;

namespace PhotoViewerWS
{
    interface IAlbumServer
    {
        [WebMethod]
        List<string> getAlbumList();

        [WebMethod]
        List<Guid> getPicturesFromAlbumName(string albumName);
    }

    interface IPictureServer
    {
        [WebMethod]
        string PictureName(Guid picIdentifier);
        [WebMethod]
        Bitmap PictureData(Guid picIdentifier);
        [WebMethod]
        int PictureRating(Guid picIdentifier);
    }

    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [ToolboxItem(false)]
    
    public class Service1 : System.Web.Services.WebService, IAlbumServer, IPictureServer 
    {
        #region IPictureServer Members
        [WebMethod]
        string IPictureServer.PictureName(Guid picIdentifier)
        {
            return ((Photo)Util.getPhotoById(picIdentifier)).name;
        }

        [WebMethod]
        Bitmap IPictureServer.PictureData(Guid picIdentifier)
        {
            return new Bitmap(((Photo)Util.getPhotoById(picIdentifier)).image);
        }

        [WebMethod]
        int IPictureServer.PictureRating(Guid picIdentifier)
        {
            return ((Photo)Util.getPhotoById(picIdentifier)).rating;
        }

        #endregion

        #region IAlbumServer Members

        [WebMethod]
        List<string> IAlbumServer.getAlbumList()
        {
            List<Category> clist = Util.getListCategory();
            List<string> cnames = new List<string>();
            foreach (Category c in clist)
            {
                cnames.Add(c.name);
            }
            return cnames;
        }

        [WebMethod]
        List<Guid> IAlbumServer.getPicturesFromAlbumName(string albumName)
        {
            List<Category> clist = Util.getListCategory();
            List<Guid> retList = new List<Guid>();
            foreach (Category c in clist)
            {
                if (c.name.Equals(albumName))
                {
                    foreach (Photo p in c.photos)
                    {
                        retList.Add(p.uid);
                    }
                }
            }
            return retList;
        }

        #endregion
    }
}
